package com.rabbit.mq.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum BindingEnum {

//    simple_binding(ExchangeEnum.direct_name, QueueEnum.simple, null),
//
//    work_binding(ExchangeEnum.direct_name, QueueEnum.work, null),

    publish_subscribe_binding1(ExchangeEnum.fanout_exchange, QueueEnum.publish_subscribe1_queue, null),
    publish_subscribe_binding2(ExchangeEnum.fanout_exchange, QueueEnum.publish_subscribe2_queue, null),

    routing_binding1(ExchangeEnum.topic_exchange, QueueEnum.routing1_queue, null),
    routing_binding2(ExchangeEnum.topic_exchange, QueueEnum.routing2_queue, null),

    topics_binding1(ExchangeEnum.topic_exchange, QueueEnum.topics1_queue, null),
    topics_binding2(ExchangeEnum.topic_exchange, QueueEnum.topics2_queue, null),

    deal_binding(ExchangeEnum.deal_exchange, QueueEnum.deal_queue, null),

    reply_binding(ExchangeEnum.reply_exchange, QueueEnum.reply_queue, null),

    async_binding(ExchangeEnum.async_exchange, QueueEnum.async_queue, null),

    batch_binding(ExchangeEnum.batch_exchange, QueueEnum.batch_queue, null),
    ;

    /**交换机*/
    private ExchangeEnum exchangeEnum ;
    /*队列路由键(注意匹配，例如:路由键“news"将会匹配到指定路由器下路由键为: [bIog news, * news] 的队列) */
    private QueueEnum queueEnum;
    /*binding的参数*/
    private Map<String, Object> arguments;

    public static List<BindingEnum> toList() {
        return new ArrayList<>(Arrays.asList(BindingEnum.values()));
    }

    public static ExchangeEnum getExchangeEnum(QueueEnum queueEnum){
        for(BindingEnum bindingEnum: BindingEnum.values()){
            if (bindingEnum.queueEnum.equals(queueEnum)){
                return bindingEnum.getExchangeEnum();
            }
        }
        return null;
    }
}
